package fractal;

import fractal.fractal.Fractal;
import fractal.fractal.FractalData;

import java.util.ArrayList;

public class FractalRecorder
{
	private final ArrayList<FractalData> records = new ArrayList<>();
	private int maxP = -1, currentP = -1;
	public FractalRecorder()
	{
	}
	public void recordNewData(Fractal fractal)
	{
		currentP++;
		if (currentP < records.size())
		{
			fractal.center();
			records.get(currentP).setRecordData(fractal);
		} else
		{
			records.add(fractal.getNewRecordData());
		}
		maxP = currentP;
	}

	public void recordNewData(FractalData data)
	{
		maxP++;
		if (maxP < records.size())
		{
			records.get(maxP).setRecordData(data);
		} else
		{
			records.add(data.clone());
		}
	}

	public void initRecordData(Fractal fractal)
	{
		currentP = -1;
		recordNewData(fractal);
	}

	public void recordCurrentData(Fractal fractal)
	{
		if (currentP < records.size() && currentP >= 0)
		{
			fractal.center();
			records.get(currentP).setRecordData(fractal);
		} else
		{
			records.add(fractal.getNewRecordData());
			maxP = currentP = records.size();
		}
	}

	public FractalData getCurrentData()
	{
		if (currentP < records.size() && currentP >= 0)
			return records.get(currentP);
		return null;
	}

	public FractalData getForwardData()
	{
		if (currentP < maxP)
		{
			currentP++;
			return records.get(currentP);
		}
		return null;
	}

	public FractalData getBackwardData()
	{
		if (currentP > 0)
		{
			currentP--;
			return records.get(currentP);
		}
		return null;
	}
	public int getMaxP()
	{
		return maxP;
	}
	public int getCurrentP()
	{
		return currentP;
	}
}
